import { filePost, request } from "@/utils/http.js";

import globalConfig from "@/utils/config.js";

const ssoUrl = globalConfig.ssoUrl;
const baseUrl = globalConfig.microUrl;
const apiUrl = globalConfig.baseUrl;

export default {
  login: (data) => {
    return request({
      url: `${baseUrl}/uc/userV2/login`,
      method: "POST",
      data
    });
  },
  register: (data) => {
    return request({
      url: `${baseUrl}/member/register`,
      method: "POST",
      data
    });
  },
  getUserInfo: (data) => {
    return request({
      url: `${baseUrl}/member/getInfo`,
      method: "GET",
      data
    });
  },
  loginOut: (data) => {
    return request({
      url: `${baseUrl}/uc/userV2/logout`,
      method: "POST",
      data
    });
  },
  loginSsoStepOne: (data) => {
    // 多步骤登录1
    return request({
      url: `${ssoUrl}/user/sso/loginFirstStep`,
      method: "POST",
      data
    });
  },
  loginSsoStepTwo: (data) => {
    // 多步骤登录2
    return request({
      url: `${ssoUrl}/user/sso/loginSecondStep`,
      method: "POST",
      data
    });
  },
  changeCompany: (data) => {
    // 切换公司
    return request({
      url: `${ssoUrl}/user/sso/changeCompany`,
      method: "POST",
      data
    });
  },
  findCompanyList: (data) => {
    // 获取公司列表
    return request({
      url: `${ssoUrl}/user/sso/listCompany`,
      method: "GET",
      data
    });
  },
  // 更新用户信息
  updateInfo: (data) => {
    return request({
      url: `${baseUrl}/member/update`,
      method: "POST",
      data
    });
  },
  // 订单报表
  orderInfo: (data) => {
    return request({
      url: `${baseUrl}/sa/sale/getStatisticsSaleReport`,
      method: "GET",
      data
    });
  },
  // 获取用户列表
  userList: (data) => {
    return request({
      url: `${baseUrl}/uc/user/search`,
      method: "GET",
      data
    });
  },
  // 客户统计
  customerCount: (data) => {
    return request({
      url: `${baseUrl}/crm/customerPrivate/findCustomerStatistic`,
      method: "GET",
      data
    });
  },
  noticeSwitch: (data) => {
    return request({
      url: `${baseUrl}/sys/message/setStatus`,
      method: "POST",
      data
    });
  },
  noticeList: (data) => {
    return request({
      url: `${baseUrl}/sys/message/page`,
      method: "GET",
      data
    });
  },
  noticeStatus: (data) => {
    return request({
      url: `${baseUrl}/sys/message/statusCount`,
      method: "GET",
      data
    });
  },
  // 获取红包余额
  getAccountMoney: (data) => {
    return request({
      url: `${baseUrl}/uc/account/get`,
      method: "GET",
      data
    });
  },
  // 上传头像
  uploadFile: (data) => {
    return filePost({
      url: `${apiUrl}/member/uploadPortrait`,
      filePath: data.filePath,
      data: data.formData
    });
  },
  // 获取图形验证码
  getCaptcha: () => {
    return new Promise((resolve, reject) => {
      wx.request({
        url: `${baseUrl}/uc/userV2/getCaptcha`,
        responseType: "arraybuffer",
        success(res) {
          let base64 = wx.arrayBufferToBase64(res.data);
          base64 = `data:image/jpeg;base64,${base64}`;
          resolve(base64);
        }
      });
    });
  },
  // 获取手机验证码
  getSms: (data) => {
    return request({
      url: `${baseUrl}/sys/sms/sendSms`,
      method: "POST",
      data
    });
  },
  // 修改密码
  updatePwd: (data) => {
    return request({
      url: `${baseUrl}/member/savePassword`,
      method: "POST",
      data
    });
  },
  changePassword: (data) => {
    return request({
      url: `${baseUrl}/member/changePassword`,
      method: "POST",
      data
    });
  },
  verifyWxBind: (data) => {
    // 验证当前登陆账户是否与微信用户绑定关系
    return request({
      url: `${baseUrl}/member/verifyWxBind`,
      method: "POST",
      data
    });
  },
  userEditBindWx: (data) => {
    // 用户变更绑定微信号
    return request({
      url: `${baseUrl}/member/userEditBindWx`,
      method: "POST",
      data
    });
  },
  bindWxMsg: (data) => {
    // 用户消息通知-开关
    return request({
      url: `${baseUrl}/member/bindWxMsg`,
      method: "POST",
      data
    });
  },
  // 生成小程序二维码
  getWxaCodeUnLimit: (data) => {
    return request({
      url: "https://api.youliao.com" + "/uc/user/wx/getWxaCodeUnLimit",
      method: "POST",
      data
    });
  },

  // 生成小程序二维码
  getWxaCodeUnLimit2: (data) => {
    return request({
      url: `${baseUrl}/uc/user/wx/getWxaCodeUnLimit`,
      method: "POST",
      data
    });
  }
};
